package entity

import "github.com/lab-online/internal/shared/valueobject"

func AddStudents(students ...string) ClassOption {
	return func(c *Class) {
		existingStudents := make(map[string]bool, len(c.Students)+len(students))
		for _, studentVO := range c.Students {
			existingStudents[studentVO.GetUsername()] = true
		}

		for _, student := range students {
			if !existingStudents[student] {
				c.Students = append(c.Students, &valueobject.User{
					Username: student,
				})
				existingStudents[student] = true
			}
		}
	}
}
func RemoveStudents(students ...string) ClassOption {
	return func(c *Class) {
		existingStudents := make(map[string]bool, len(c.Students))
		for _, studentVO := range c.Students {
			existingStudents[studentVO.GetUsername()] = true
		}
		for _, student := range students {
			delete(existingStudents, student)
		}
		c.Students = make([]valueobject.UserVO, len(existingStudents))
		i := 0
		for student := range existingStudents {
			c.Students[i] = &valueobject.User{
				Username: student,
			}
			i++
		}
	}
}
